package com.jinzhu.service.impl;

import com.jinzhu.dao.EmpMapper;
import com.jinzhu.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

import static java.util.stream.Collectors.toList;

@Service
public class EmpServiceImpl implements EmpService {
    @Autowired
    EmpMapper empMapper;


    @Override
    public List<Map<String, Object>> empGenderData() {
        // 从数据库中获取员工性别数据
        List<Map<String, Object>> result = empMapper.empGenderData().stream().map(item -> {
            Map<String, Object> newMap = new HashMap<>();
            Integer gender = (Integer) item.get("gender");
            // 当性别字段不为空时，根据性别值设置名称字段
            if (gender != null) {
                if (gender == 1) {
                    newMap.put("name", "男性员工");
                } else if (gender == 2) {
                    newMap.put("name", "女性员工");
                }
            }
            newMap.put("value", item.get("count(id)"));
            return newMap;
        }).toList();
        // 返回处理后的员工性别数据
        return result;
    }

    @Override
    public Map<String, Object> empJobData() {
        List<String> empJobNames = new ArrayList<>();
        List<Object> empJobCounts = new ArrayList<>();
        empMapper.empJobData().forEach(item -> {
            String empJobName ="";
            Integer job = item.get("job")!=null?(Integer) item.get("job"):0;
            if (job==1){
                empJobName="行政人员";
            } else if (job==2) {
                empJobName="教师";
            }else if (job==3){
                empJobName="教研人员";
            } else if (job==4) {
                empJobName="咨询师";
            } else if (job==5) {
                empJobName="就业指导师";
            } else if (job==6) {
                empJobName="人事";
            }else {
                empJobName="其他";
            }

            empJobNames.add(empJobName);
            empJobCounts.add(item.get("count(id)"));

        });

        Map<String, Object> result = new LinkedHashMap<>();
        result.put("empJobNames", empJobNames);
        result.put("empJobCounts", empJobCounts);
        return result;

    }
}








